import { FGTeamItem } from "./FGTeamItem";
import { FGLineLink } from "./FGLineLink";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FootBallGameConst } from "./FootBallGameConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { FGTeamInfo } from "./FGTeamInfo";
import { Cache } from "../../cache/Cache";
import { SFootballGameInfo } from "../../../../Message/Game/SFootballGameInfo";
import { DataEvent } from "../../events/DataEvent";
import { Language } from "../../../../extend/language/Language";
type int = number;
//class FGSelectItemBase
    
    export  class FGSelectItemBase /* flash.display.Sprite */
    {
        constructor(arg1: Boolean)
        {
            
            this._isLeft = arg1;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=NaN;
            this._teamItemA = new FGTeamItem();
            this._teamItemA.isResult = true;
            this.addChild(this._teamItemA);
            this._teamItemB = new FGTeamItem();
            this._teamItemB.isResult = true;
            this._teamItemB.y = 40;
            this.addChild(this._teamItemB);
            this.lineLink = new FGLineLink();
            this.lineLink.x = 67;
            this.lineLink.y = 9.5;
            this.addChild(this.lineLink);
            this._teamItemSelect = new FGTeamItem();
            this._teamItemSelect.x = 109;
            this._teamItemSelect.y = 22;
            this.addChild(this._teamItemSelect);
            this._timeTxt = ObjCreate.createTextField("", -21, 19, 220, 20, this, new GTextFormat(null, null, FootBallGameConst.matchTimeColor));
            this._timeTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._timeTxt.multiline = true;
            this._timeTxt.mouseEnabled = false;
            this._resultTxt = ObjCreate.createTextField("", 165, 100, 220, 20, this, GlobalStyle.textFormat6);
            this._resultTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._resultTxt.visible = false;
            if (!this._isLeft) 
            {
                loc1 = 111;
                this._teamItemA.x = loc1;
                this._teamItemA.y = 0;
                this._teamItemB.x = loc1;
                this._teamItemB.y = 40;
                this._teamItemSelect.x = 0;
                this._teamItemSelect.y = 19;
                this._timeTxt.x = 91;
                this._timeTxt.y = 19;
                this._resultTxt.x = 0;
                this.lineLink.scaleX = -1;
                this.lineLink.x = 86;
                this.lineLink.y = 7.5;
            }
            this.enableSelect(false);
            return;
        }

        /* internal  */onResLoadHandler(): void
        {
            return;
        }

        /* internal  */onSelectChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=false;
            var loc2=null;
            var loc3=null;
            return;
        }

        /* internal  */onAlertClickHander(arg1: Boolean): void
        {
            if (!(!arg1 && this._teamInfo && this._gameInfo.guess == 0)) 
            {
            };
            return;
        }

        public updateByTeamInfo(arg1: FGTeamInfo): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=false;
            this._teamInfo = arg1;
            if (arg1) 
            {
                this._gameInfo = this._teamInfo.gameInfo;
                this._teamItemA.updateTeamInfo(this._gameInfo.teamA, this._gameInfo.teamAName);
                this._teamItemB.updateTeamInfo(this._gameInfo.teamB, this._gameInfo.teamBName);
                this._teamItemA.teamInfo = this._teamInfo;
                this._teamItemB.teamInfo = this._teamInfo;
                this.lineLink.teamInfo = this._teamInfo;
                this._timeTxt.htmlText = this.getGuessDateTip(this._gameInfo.gameDt);
                loc1 = new FGTeamInfo();
                if (arg1.isHasResult) 
                {
                    this._teamItemSelect.updateTeamInfo(arg1.winerId, arg1.winerName);
                    loc1.gameInfo = Cache.instance.footballGuess.get8To4Info(this._gameInfo);
                    this._resultTxt.visible = true;
                    this._teamItemSelect.isResult = true;
                    this.enableSelect(false);
                }
                else 
                {
                    if (arg1.isHasGuess) 
                    {
                        this._teamItemA.isSelected = arg1.isGuessA;
                        this._teamItemB.isSelected = !arg1.isGuessA;
                        this.enableSelect(false);
                    }
                    else 
                    {
                        this._teamItemA.isSelected = false;
                        this._teamItemB.isSelected = false;
                        this._teamItemSelect.isResult = false;
                        loc3 = Cache.instance.footballGuess.isCanGuess(this._gameInfo);
                        this.enableSelect(loc3);
                    }
                    loc2 = new SFootballGameInfo();
                    loc2.type = FootBallGameConst.GROUP_TYPE_4;
                    if (this._gameInfo.group < 5) 
                    {
                        if (this._gameInfo.group < 3) 
                        {
                            loc2.group = 1;
                        }
                        else 
                        {
                            loc2.group = 2;
                        }
                    }
                    else if (this._gameInfo.group < 7) 
                    {
                        loc2.group = 3;
                    }
                    else 
                    {
                        loc2.group = 4;
                    }
                    loc1.gameInfo = loc2;
                }
                this._teamItemSelect.teamInfo = loc1;
            }
            return;
        }

        public enableSelect(arg1: Boolean): void
        {
            this._teamItemA.isEnable = arg1;
            this._teamItemB.isEnable = arg1;
            return;
        }

        /* internal  */updateSelectTeamByDict(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            var loc1=arg1["type"] as int;
            var loc2=arg1["group"] as int;
            var loc3=arg1["team"] as int;
            if (this._gameInfo && this._gameInfo.group == loc2 && this._gameInfo.type == loc1) 
            {
                if (loc3 != this._gameInfo.teamA) 
                {
                    this._teamItemSelect.updateTeamInfo(this._gameInfo.teamB, this._gameInfo.teamBName);
                }
                else 
                {
                    this._teamItemSelect.updateTeamInfo(this._gameInfo.teamA, this._gameInfo.teamAName);
                }
                this._teamItemSelect.isSelected = true;
                this.enableSelect(false);
            }
            return;
        }

        /* internal  */onFootballGuessTeamSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as Map<any, any> /* flash.utils.Dictionary */;
            this.updateSelectTeamByDict(loc1);
            return;
        }

        /* internal  */getGuessDateTip(arg1: Date): string
        {
            var loc1="";
            var loc2=arg1.month + 1;
            var loc3=arg1.date;
            var loc4=arg1.hours;
            var loc5=arg1.minutes;
            var loc6=Language.getString(51141).split(",");
            loc1 = this.twoBitNum(loc2) + loc6[1] + this.twoBitNum(loc3) + loc6[2] + " " + this.twoBitNum(loc4) + ":" + this.twoBitNum(loc5);
            return loc1;
        }

        /* internal  */twoBitNum(arg1: int): string
        {
            return arg1 >= 10 ? arg1.toString() : "0" + arg1;
        }

        public cloneDate(arg1: Date): Date
        {
            var loc1=new Date();
            loc1.setFullYear(arg1.fullYear);
            loc1.setMonth(arg1.month);
            loc1.setDate(arg1.date);
            loc1.setHours(arg1.hours);
            loc1.setMinutes(arg1.minutes);
            loc1.setSeconds(arg1.seconds);
            return loc1;
        }

        /* internal */ /* var */_teamItemA: FGTeamItem;

        /* internal */ /* var */_teamItemB: FGTeamItem;

        /* internal */ /* var */_teamItemSelect: FGTeamItem;

        /* internal */ /* var */_timeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_resultTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_playTimeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_teamInfo: FGTeamInfo;

        /* internal */ /* var */_gameInfo: SFootballGameInfo;

        /* internal */ /* var */_isLeft: Boolean;

        /* internal */ /* var */lineLink: FGLineLink;
    }
